package com.xiliu.server.modules.basicdata.controller;

import com.xiliu.common.controller.BaseController;
import com.xiliu.common.enums.BusinessType;
import com.xiliu.common.result.R;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.xiliu.common.annotation.Log;
import com.xiliu.server.common.utils.ExcelUtils;
import com.xiliu.server.modules.basicdata.entity.XlHouse;
import com.xiliu.server.modules.basicdata.service.IXlHouseService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xiliu.common.page.TableDataInfo;


/**
 * 房源表Controller
 * 
 * @author xiliu
 * @date 2022-11-08
 */
@RestController
@RequestMapping("/basic/house")
public class XlHouseController extends BaseController {
    @Autowired
    private IXlHouseService xlHouseService;

    /**
     * 查询房源表列表
     */
    @PreAuthorize("@customSs.hasPermi('basic:house:list')")
    @GetMapping("/list")
    public TableDataInfo list(XlHouse xlHouse) {
        startPage();
        List<XlHouse> list = xlHouseService.selectXlHouseList(xlHouse);
        return getDataTable(list);
    }

    /**
     * 导出房源表列表
     */
    @PreAuthorize("@customSs.hasPermi('basic:house:export')")
    @Log(title = "房源表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, XlHouse xlHouse) {
        List<XlHouse> list = xlHouseService.selectXlHouseList(xlHouse);
        ExcelUtils.exportEasyExcel(response,XlHouse.class,list,"房源表数据");
    }

    /**
     * 获取房源表详细信息
     */
    @PreAuthorize("@customSs.hasPermi('basic:house:query')")
    @GetMapping(value = "/{houseId}")
    public R getInfo(@PathVariable("houseId") Long houseId) {
        return R.ok(xlHouseService.selectXlHouseByHouseId(houseId));
    }

    /**
     * 新增房源表
     */
    @PreAuthorize("@customSs.hasPermi('basic:house:create')")
    @Log(title = "房源表", businessType = BusinessType.INSERT)
    @PostMapping("/create")
    public R create(@RequestBody XlHouse xlHouse) {
        boolean success = xlHouseService.create(xlHouse);
        if (success) {
            return R.ok();
        }
        return R.error("添加失败");
    }

    /**
     * 修改房源表
     */
    @PreAuthorize("@customSs.hasPermi('basic:house:edit')")
    @Log(title = "房源表", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/update/{houseId}")
    public R update(@PathVariable Long houseId,  @RequestBody XlHouse xlHouse) {
        xlHouse.setHouseId(houseId);
        boolean success = xlHouseService.update(xlHouse);
        if (success) {
            return R.ok();
        }
        return R.error("修改失败");
    }

    /**
     * 删除房源表
     */
    @PreAuthorize("@customSs.hasPermi('basic:house:remove')")
    @Log(title = "房源表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{houseIds}")
    public R remove(@PathVariable Long[] houseIds) {
        return R.ok(xlHouseService.deleteXlHouseByHouseIds(houseIds));
    }
}
